var app = getApp();

Page({
  data: {
    imgFlag: [],
    addressBoo: !0,
    provinceBoo: !0,
    text: "",
    city: "",
    intro: "",
    tapFlag: !0,
    height: 500,
    textFlag: !0,
    typeHeight: 400,
    sexArray: ["线上科室", "自由团体"],
    sexIndex: "",
    data_arr: [],
  },
  bindSexChange: function (a) {
    console.log(a), this.setData({
      sexIndex: a.detail.value
    }), 0 == a.detail.value && (this.data.teamType = 1), 1 == a.detail.value && (this.data.teamType = 2);
  },
  chooseImage: function () {
    var that = this;
    var uniacid = that.data.uniacid
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // console.log(res)
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths[0];
        console.log(tempFilePaths);
        wx.uploadFile({
          url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=upload&m=hyb_yl',
          filePath: tempFilePaths,
          name: 'upfile',
          formData: {},
          success: function (res) {
            console.log(res.data)
            that.setData({
              uplogo: res.data
            })
          },
          fail: function (res) {
            console.log(res)
          },
        })
        that.setData({
          logo: tempFilePaths
        })
      }
    })
  },

  getText: function (a) {
    this.setData({
      text: a.detail.value
    });
  },
  getIntro: function (a) {
    this.setData({
      intro: a.detail.value
    });
  },
  bindlinechange: function (a) {
    1 != this.data.type ? a.detail.heightRpx > 500 && this.setData({
      height: a.detail.heightRpx
    }) : a.detail.heightRpx > 400 && this.setData({
      typeHeight: a.detail.heightRpx
    });
  },
  getCity: function (a) { },
  save: function () {
    var that = this
    var teamname = that.data.text
    var teamaddress = that.data.address
    var teamtext = that.data.intro
    var teamtype = that.data.sexIndex
    var teampic = that.data.teampic1
    var t_id = that.data.t_id
    app.util.request({
      'url': 'entry/wxapp/Studio.docteam',
      data: {
        teamname: teamname,
        teamaddress: teamaddress,
        teamtext: teamtext,
        teamtype: teamtype,
        teampic: teampic,
        zid: that.data.zid,
        t_id: t_id
      },
      success: function (res) {
        console.log(res)
        wx.showToast({
          title: "保存成功",
          icon: "none",
          duration: 2e3,
          success: function () {
            setTimeout(function () {
              wx.navigateBack({
                delta: 1
              })
            }, 1000)
          }
        })
      }
    })
  },
  creat: function () {
    var that = this
    var teamname = that.data.text
    var teamaddress = that.data.address
    var teamtext = that.data.intro
    var teamtype = that.data.sexIndex

    if (teamname == '') {
      wx.showToast({
        title: "请填写团队名称",
        icon: "none",
        duration: 2e3
      })
    } else if (teamaddress == undefined) {
      wx.showToast({
        title: "请选择团队所在地区",
        icon: "none",
        duration: 2e3
      })
    } else if (teamtype == undefined) {
      wx.showToast({
        title: "请选择团队类型",
        icon: "none",
        duration: 2e3
      })
    } else if (teamtext == '') {
      wx.showToast({
        title: "请填写团队简介",
        icon: "none",
        duration: 2e3
      })
    } else {
      var teampic = that.data.uplogo
      app.util.request({
        'url': 'entry/wxapp/Studio.docteam',
        data: {
          teamname: teamname,
          teamaddress: teamaddress,
          teamtext: teamtext,
          teamtype: teamtype,
          teampic: teampic,
          zid: that.data.zid
        },
        success: function (res) {
          console.log(res)
          wx.showToast({
            title: "创建成功",
            icon: "none",
            duration: 2e3,
            success: function () {
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1
                })
              }, 1000)
            }
          })
        }
      })

    }

  },
  onLoad: function (t) {
    var that = this;
    var zid = t.zid
    var uniacid = app.siteInfo.uniacid;
    if (t.t_id) {
      app.util.request({
        'url': 'entry/wxapp/Studio.selectteaminfo',
        data: {
          t_id: t.t_id,
          zid: zid
        },
        success: function (res) {
          console.log(res)
          that.setData({
            logo: res.data.teampic,
            teampic1: res.data.teampic1,
            text: res.data.teamname,
            address: res.data.teamaddress,
            sexIndex: res.data.teamtype,
            intro: res.data.teamtext,
            managerRole: res.data.managerRole,
            type: res.data.type,
            t_id: t.t_id
          })
        },
      })
    }
    app.util.request({
      'url': 'entry/wxapp/Hzbingli.url',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data
        })
      },
    })
    that.setData({
      uniacid: uniacid,
      zid: zid
    })
  },
  onReady: function () { },
  onShow: function () {
    var a = wx.createAnimation({
      duration: 800,
      timingFunction: "ease"
    });
    this.animation = a;
  },
  //用户选择收货地址
  chooseLocation: function () {
    var that = this;
    if (wx.chooseAddress) {
      wx.chooseAddress({
        success: function (res) {
          console.log(JSON.stringify(res));

          var address = res.provinceName + res.cityName + res.countyName + res.detailInfo
          console.log(res);
          that.setData({
            address: address,
            //具体收货地址显示
            flag: false,
          })
        },
        fail: function (err) {
          console.log(JSON.stringify(err));
          console.info("收货地址授权失败");

        }
      })
    } else {
      console.log('当前微信版本不支持chooseAddress');
    }
  },
  tapProvince: function (t) {
    this.setData({
      cityList: ""
    });
    var e = t.target.id,
      o = t.target.dataset.index,
      i = t.target.dataset.province,
      n = this;
    this.setData({
      provinceIndex: o,
      province: i,
      Seng: t.currentTarget.dataset.province
    }), n.data.provinceBoo && wx.request({
      url: a.globalData.httpOne + "mall/addr/listNation/" + e,
      success: function (a) {
        200 == a.data.code && n.setData({
          cityList: a.data.data,
          cityIndex: "none",
          districtIndex: "none",
          provinceBoo: !0,
          province: i
        });
      }
    }), n.setData({
      provinceBoo: !1
    });
  },
  tapCity: function (a) {
    this.setData({
      city: "",
      textFlag: !0
    });
    var t = a.target.dataset.index,
      e = a.target.dataset.city,
      o = this.data.province;
    this.animation.translateX(1200).step(), this.setData({
      code: a.target.dataset.code,
      cityIndex: t,
      city: e,
      area: o + "-" + e,
      addressBoo: !0,
      animationData: this.animation.export(),
      SHI: a.currentTarget.dataset.city
    });
  },
  closesearea: function () {
    this.setData({
      textFlag: !0
    }), this.animation.translateX(1200).step(), this.setData({
      addressBoo: !0,
      animationData: this.animation.export()
    });
  },
  onHide: function () { },
  shanchu1: function (t) {
    var e = this;
    wx.showModal({
      title: "提示",
      content: "您确认退出团队吗？",
      success: function (t) {
        t.confirm ? wx.request({
          url: a.globalData.dic + "doctor/team/quit/" + e.data.token + "/" + e.data.teamId,
          success: function (a) {
            if (200 == a.data.code) {
              if (1 == e.data.groupFlag) return void wx.navigateBack({
                delta: 4
              });
              wx.navigateBack({
                delta: 3
              });
            }
          }
        }) : t.cancel;
      }
    });
  },
  shanchu: function (t) {
    var that = this;
    var t_id = that.data.t_id
    wx.showModal({
      content: '是否解散团队',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/seledocteam',
            data: {
              t_id: t_id,
              op: 'delete',
            },
            success: function (res) {
              console.log(res)
              wx.showToast({
                title: '解散成功',
                icon: "none",
                duration: 2e3,
                success: function () {
                  setTimeout(function () {
                    wx.navigateBack({
                      delta: 2
                    })
                  }, 2000)
                }
              })
            },
          })
        }
      }
    })

  }
});